﻿<Window xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"  
        x:Class="DocumentsTaggerUI.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:c="clr-namespace:DocumentsTagger.UI.ViewModel"
        xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase" 
        xmlns:dat="clr-namespace:System.Windows.Data;assembly=PresentationFramework"
        xmlns:dm="clr-namespace:DocumentsTagger.DM;assembly=DocumentsTaggerDM"
        xmlns:uidm="clr-namespace:DocumentsTagger.UI.Model"
        xmlns:ui="clr-namespace:DocumentsTagger.UI"
        xmlns:control="clr-namespace:LoadingControl.Control;assembly=LoadingControl"
        Title="Document Tagger" Height="414" Width="800" 
        Closing="Window_Closing" 
        WindowState="Maximized"
        ShowInTaskbar="True" Icon="/DocumentsTaggerUI;component/Resources/bookmark48.ico">

    <Window.Resources>
        <ui:BoolToFontWeightConverter x:Key="boolToFontWeightConverter" />
        <DataTemplate x:Key="FolderTemplate"
                      DataType="{x:Type uidm:FolderUIModel}">
            <Expander Header="{Binding Path=FolderName}" ToolTip="{Binding Path=FolderPath}">
                <ListBox BorderThickness="0" 
                         Width="{Binding ElementName=DocumentsPanel,
                                         Path=ActualWidth}"
                         ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                         ItemsSource="{Binding Path=Documents}"
                         SelectionChanged="ListBox_SelectionChanged"
                         >
                    <ListBox.ItemTemplate>
                        <DataTemplate DataType="{x:Type uidm:DocumentUIModel}">
                            <TextBlock Width="auto" 
                                       HorizontalAlignment="Stretch"
                                       Text="{Binding Path=FileName}" 
                                       FontWeight="{Binding IsChanged, Converter={StaticResource boolToFontWeightConverter}}" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </Expander>
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="22"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>

        <Menu Height="25" Name="MainAppMenu" HorizontalAlignment="Stretch" BorderThickness="2">
            <MenuItem Header="_File">
                <MenuItem Header="Clear DB" Command="{Binding ClearDB}" />
                <Separator />
                <MenuItem Header="_Exit" Click="MenuItem_Exit_Click" />
            </MenuItem>
            <MenuItem Header="_Scanner">
                <MenuItem IsCheckable="True" 
                          Header="Start Scanner" 
                          Command="{Binding StartScannerCommand}" 
                          CommandParameter="{Binding RelativeSource={RelativeSource Self},
                                             Path=IsChecked}"></MenuItem>
                <MenuItem Header="Scanner Options" Click="MenuItem_ScannerOptions_Click" />
            </MenuItem>
            <MenuItem Header="Tags" Click="MenuItem_Tags_click"></MenuItem>

        </Menu>
        <DockPanel Grid.Row="1" LastChildFill="True">
            <Grid DockPanel.Dock="Left" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="200px"
                                      MinWidth="100px" />
                    <ColumnDefinition Width="10px" />
                    <ColumnDefinition 
                                      MinWidth="400px"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="200px" />
                </Grid.RowDefinitions>


                <DockPanel LastChildFill="True"
                           Grid.Row="0"
                           Grid.Column="0"
                           Grid.RowSpan="2"
                           Margin="5,2,2,2"
                           x:Name="DocumentsPanel"
                           >
                    <ListView ItemsSource="{Binding Path=AvailableFolders}"
                              ItemTemplate="{StaticResource FolderTemplate}"
                              Height="Auto"
                              DockPanel.Dock="Top"
                              ScrollViewer.CanContentScroll="False"
                              >
                        
                    </ListView>
                    <!--ListBox DockPanel.Dock="Top" 
                             Height="Auto"
                             
                             ItemsSource="{Binding Path=AvailableFolders}"
                             ItemTemplate="{StaticResource FolderTemplate}"
                             >
                    </ListBox-->
                </DockPanel>

                <GridSplitter Grid.Row="0"
                          Grid.Column="1"
                          Grid.RowSpan="2"
                          Height="Auto" 
                          ResizeBehavior="PreviousAndNext"
                          HorizontalAlignment="Stretch" 
                          VerticalAlignment="Stretch" 
                          Width="10px" 
                          ShowsPreview="True" 
                          BorderThickness="1" />
                <Grid MinWidth="100" 
                  DockPanel.Dock="Bottom" 
                  MinHeight="100"
                  Grid.Column="2"
                  Grid.Row="1"
                  DataContext="{Binding SelectedDocumentViewModel,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                  >
                    <Border BorderBrush="Black" BorderThickness="1" Margin="2,2,2,2">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"></ColumnDefinition>
                                <ColumnDefinition Width="auto"></ColumnDefinition>
                                <ColumnDefinition Width="auto"></ColumnDefinition>
                                <ColumnDefinition Width="auto"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Border Height="Auto" Grid.Column="0">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"></ColumnDefinition>
                                        <ColumnDefinition Width="*"></ColumnDefinition>
                                    </Grid.ColumnDefinitions  >
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="auto"></RowDefinition>
                                        <RowDefinition Height="auto"></RowDefinition>
                                        <RowDefinition Height="auto"></RowDefinition>
                                        <RowDefinition Height="120*" />
                                    </Grid.RowDefinitions>
                                    <Label     Grid.Column="0" Grid.Row="0">File name:</Label>
                                    <TextBlock Grid.Column="1" VerticalAlignment="Center" ToolTip="{Binding FileName}" Text="{Binding FileName}" Grid.ColumnSpan="2" Margin="0,5"></TextBlock>
                                    <Label     Grid.Column="0" Grid.Row="1">Size:</Label>
                                    <TextBlock Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" Grid.ColumnSpan="2" Margin="0,5" Text="{Binding Size}"></TextBlock>
                                    <Label     Grid.Column="0" Grid.Row="2">Creation date</Label>
                                    <TextBlock Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" Grid.ColumnSpan="2" Margin="0,5" Text="{Binding CreationDate}"/>
                                </Grid>
                            </Border>
                            <Border BorderThickness="1" Width="150px" Grid.Column="1">
                                <Grid Margin="1,1,0,0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="auto"></RowDefinition>
                                        <RowDefinition Height="auto"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"></ColumnDefinition>
                                        <ColumnDefinition Width="*"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <Label Grid.Row="0" Grid.ColumnSpan="2">Accepted Tags</Label>
                                    <Label Grid.Row="1" Grid.Column="0">Add:</Label>
                                    <TextBox Grid.Row="1" 
                                             Grid.Column="1" 
                                             PreviewKeyUp="AddTag_PreviewKeyUp"
                                             Name="tbAddTag"
                                             />
                                    
                                    <ListBox Grid.Row="2"
                                             Grid.ColumnSpan="2"
                                             Margin="0,0,0,0" 
                                             ItemsSource="{Binding AcceptedTags}" 
                                             Height="auto"
                                             >
                                        <ListBox.ContextMenu>
                                            <ContextMenu>
                                                <MenuItem Header="Remove Tags" 
                                                          Name="removeAcceptedTagMI"
                                                          Command="{Binding RemoveAcceptedTagCommandProp,UpdateSourceTrigger=LostFocus,Mode=TwoWay}"
                                                          />
                                            </ContextMenu>
                                        </ListBox.ContextMenu>
                                        <ListBox.ItemTemplate>
                                            <HierarchicalDataTemplate>
                                                <StackPanel Orientation="Horizontal">
                                                    <CheckBox IsChecked="{Binding IsChecked}"/>
                                                    <TextBlock Text="{Binding Name}" />
                                                </StackPanel>
                                            </HierarchicalDataTemplate>
                                        </ListBox.ItemTemplate>
                                    </ListBox>
                                </Grid>
                            </Border>
                            <Border BorderThickness="1" Width="150px" Grid.Column="2">
                                <Grid Margin="1,1,0,0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="auto"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <Label Grid.Row="0">Suggested Tags</Label>
                                    <ListBox Grid.Row="1"
                                             Margin="0,0,0,0"
                                             ItemsSource="{Binding SuggestedTags,UpdateSourceTrigger=PropertyChanged}"
                                             Height="auto">
                                        <ListBox.ContextMenu>
                                            <ContextMenu>
                                                <MenuItem Header="Accept suggested tags" Name="accepSuggestedTagMI" Command="{Binding AcceptSuggestedTagCommandProp,UpdateSourceTrigger=LostFocus,Mode=TwoWay}"></MenuItem>
                                                <MenuItem Header="Decline suggested tags" Name="declineSuggestedTagMI" Command="{Binding DeclineSugestedTagCommandProp,UpdateSourceTrigger=LostFocus,Mode=TwoWay}"></MenuItem>
                                            </ContextMenu>
                                        </ListBox.ContextMenu>
                                        <ListBox.ItemTemplate>
                                            <HierarchicalDataTemplate>
                                                <StackPanel Orientation="Horizontal">
                                                    <CheckBox IsChecked="{Binding IsChecked}"/>
                                                    <TextBlock Text="{Binding Name}" />
                                                </StackPanel>
                                            </HierarchicalDataTemplate>
                                        </ListBox.ItemTemplate>
                                    </ListBox>
                                </Grid>
                            </Border>
                            <Border BorderThickness="1" Width="150px" Grid.Column="3">
                                <Grid Margin="1,1,0,0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="auto"></RowDefinition>
                                        <RowDefinition Height="auto"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="auto"></ColumnDefinition>
                                        <ColumnDefinition Width="*"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <Label Grid.Row="0" Grid.ColumnSpan="2">Declined Tags</Label>
                                    <Label Grid.Row="1" Grid.Column="0">Add:</Label>
                                    <TextBox Grid.Row="1" 
                                             Grid.Column="1" 
                                             PreviewKeyUp="tbAddDeclinedTag_PreviewKeyUp"
                                             Name="tbAddDeclinedTag"
                                             />

                                    <ListBox Grid.ColumnSpan="2"
                                             Grid.Row="2"
                                             Margin="0,0,0,0"
                                             ItemsSource="{Binding DeclinedTags}"
                                             Height="auto">
                                        <ListBox.ContextMenu>
                                            <ContextMenu>
                                                <MenuItem Header="Remove tags" Name="removeDeclinedTagMI" Command="{Binding RemoveDeclinedTagCommandProp,UpdateSourceTrigger=LostFocus,Mode=TwoWay}"></MenuItem>
                                            </ContextMenu>
                                        </ListBox.ContextMenu>
                                        <ListBox.ItemTemplate>
                                            <HierarchicalDataTemplate>
                                                <StackPanel Orientation="Horizontal">
                                                    <CheckBox IsChecked="{Binding IsChecked}"/>
                                                    <TextBlock Text="{Binding Name}" />
                                                </StackPanel>
                                            </HierarchicalDataTemplate>
                                        </ListBox.ItemTemplate>
                                    </ListBox>
                                </Grid>
                            </Border>
                        </Grid>
                    </Border>
                </Grid>
                <Grid MinWidth="400"
                  Grid.Row="0"
                  Grid.Column="2">
                    <WindowsFormsHost Name="WindowsFormsHost" Visibility="Hidden"></WindowsFormsHost>
                    <control:LoadingAnimation Name="LoadingControl" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Hidden"/>

                </Grid>
            </Grid>
        </DockPanel>
    </Grid>
</Window>
